package cn;

import com.interview.javabasic.JUC.A;
import sun.reflect.generics.tree.Tree;

import java.rmi.MarshalException;
import java.util.*;

/*
@李子宁
Happy,happy everyday!
冲鸭！
2021/3/16

*/
public class Compiling {
    public static void main(String[] args) {
        int[] nums = {0,1,2,2,2,2,2,2,2,2,1,3};
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i],i);
        }
        int left = 0;int right = nums.length - 1;
        while(left < right){
            Integer pos = map.get(right);
        }



    }

    public int comeTwice(int[] n){
        Arrays.sort(n);
        for(int i = 0;i < n.length-1;i++){
            if(n[i] == n[i+1]){
                return n[i];
            }
        }
        return -1;
    }

    public int[] spiralOrder(int[][] matrix) {
        int m = matrix.length;
        int n = matrix[0].length;
        int[] res = new int[m*n];
        boolean[][] flag = new boolean[m][n];
        int pos = 0;
        int i = 0;int j = 0;
        while(pos < res.length){
            while(j < n){
                if(flag[i][j]) break;
                res[pos] = matrix[i][j];
                flag[i][j] = true;
                j++;
                pos++;
            }

            while(i < m){
                if(flag[i][j]) break;
                res[pos] = matrix[i][j];
                flag[i][j] = true;
                i++;
                pos++;

            }
            while(j >= 0){
                if(flag[i-1][j]) break;
                res[pos++] = matrix[i][j--];
                flag[i][j+1] = true;

            }
            while(i >= 0){
                if(flag[i-1][1+j]) break;
                res[pos++] = matrix[i--][j];
                flag[i+1][j] = true;
            }
        }
        return res;
    }

    public static int max(String s){
        int res = 0;
        Deque<Character> queue = new LinkedList<>();
        for (int i = 0; i < s.length(); i++) {
            if(queue.contains(s.charAt(i))){
                while(queue.contains(s.charAt(i))){
                    queue.removeFirst();
                }
                queue.addLast(s.charAt(i));
            }else{
                queue.addLast(s.charAt(i));
            }
            res = Math.max(res,queue.size());
        }
        res = Math.max(res,queue.size());
        return res;
    }
}
